<template>
	<view class="pubdymanic">
		<u-navbar title="发布动态" :border-bottom="false" back-icon-color="#ffffff" title-color="#fff" :background="{backgroundColor:'#000'}"></u-navbar>
		<view style="height: 50rpx;"></view>
		<view class="cellinfo">
			<view class="infoitem">
				<textarea type="text" style="line-height: 50rpx;" auto-height v-model="content" placeholder="写点什么吧..."></textarea>
			</view>
			<view class="photo">
				<u-upload name="image" :custom-btn="true" width="190" height="190"
					:form-data="formdata" @on-uploaded="daitudy" :max-count="6"
					ref="uUpload" :action="action" :auto-upload="false" >
					<view slot="addBtn" class="slot-btn" style="display: flex;justify-content: center;align-items: center;
						width: 190rpx;height: 190rpx;margin-left: 10rpx;">
						<image src="../../static/imageAdd.png" style="width: 108rpx;height: 103rpx;"></image>
					</view>
				</u-upload>
			</view>
			<view style="height: 50rpx;"></view>
		</view>
		<view style="height: 120rpx;"></view>
		<u-toast ref="uToast" />
		<u-action-sheet :list="dycatelist" @click="dycateclick" v-model="dycateshow"></u-action-sheet>
		<view class="vie-bott">
			<button class="bu-bott" @click="submit">发布</button>
		</view>
		
		<u-popup v-model="show" mode="center" width="85%" :closeable="true"
			close-icon-color="#B2B2B2" close-icon-size='40'>
			<view style="background: #2C2C2C;color: #fff;height: 100%;width: 100%;">
				<view style="height: 130rpx;"></view>
				<view style="text-align: center;margin-top: 30rpx;font-size: 30rpx;">完成真人认真或者会员才可以发布动态</view>
				<view style="height: 40rpx;"></view>
				<view class="bottomOne" @click="nav('renzheng')">立即认证</view>
				
				<view class="bottomTwo" v-if="platform==''" @click="nav('member')">开通会员</view>
				<view style="height: 50rpx;"></view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				showaddpopup: false,
				zhuti: '',
				content:'',
				action: this.$HOSTURL + '/api/Tool/imagesUpload',
				imglist: [],
				dycateshow:false,
				dycatelist:[],
				formdata:{
					water: 1,
					thumb: 1,
					user_id: this.$store.state.userid
				},
				city: ''
			}
		},
		onLoad(option) {
			uni.getStorage({
				key:'dyCity',
				success:(res)=>{
					console.log(res.data)
					this.city = res.data
				}
			})
			this.zhuti = option.cate
			this.getcate()
		},
		onShow() {
			if(this.$store.state.userinfo.is_identity_authentication != 2){
				this.show = true
				return
			}
		},
		methods: {
			async getcate() {
				const {
					data: res
				} = await this.$Request({
					url: 'apis/home/dymanic/category'
				})
				res.result.forEach(item=>{
					return item.text = item.name
				})
				console.log(res.result)
				this.dycatelist = res.result
			},
			daitudy(lists, name){
				var imglist = []
				lists.forEach(item=>{
					imglist.push(item.response.data.image)
				})
				this.imglist = imglist
				this.pubdymanic()
			},
			submit(){
				if(this.$store.state.userinfo.is_identity_authentication != 2){
					this.show = true
					return
				}
				// return console.log(this.categoryid)
				if(!this.$store.state.hasLogin) return this.$refs.uToast.show({title: '未登录',type: 'warning'})
				if(!this.content) return this.$refs.uToast.show({title: '请填写约会内容',type: 'warning'})
				let files = this.$refs.uUpload.lists
				if(files.length>0){
					this.$refs.uUpload.upload()
				}else{
					this.pubdymanic()
				}
			},
			async pubdymanic(){
				const { data: res } = await this.$Request({
					url:'apis/home/Dymanic/adddymanic',
					data:this.imglist.length>0?{
						citys: this.city,
						content: this.content,
						userid: this.$store.state.userid,
						type: 0,
						category_id: this.categoryid,
						masterimg:this.imglist.join(','),
						longitude:this.$store.state.longitude,
						latitude:this.$store.state.latitude
					}:{
						citys: this.city,
						content: this.content,
						userid: this.$store.state.userid,
						type: 0,
						category_id: this.categoryid,
						longitude:this.$store.state.longitude,
						latitude:this.$store.state.latitude
					},
					method:'POST'
				})
				if(res.code==200){
					this.content = ''
					this.$refs.uUpload.clear()
					this.imglist = []
					this.$refs.uToast.show({title: '发布成功',type: 'success',url:'/pages/dymanic/index',isTab:true})
				}
			},
			dycateclick(index) {
				this.zhuti = this.dycatelist[index].text
				console.log(this.categoryid)
			},
			nav(url, params, value) {
				this.show = false
				uni.navigateTo({
					url: `/pages/${url}/index${params?'?'+params+'='+value:''}`
				})
			},
		},
		computed:{
			categoryid(){
				var cateid
				this.dycatelist.forEach(item=>{
					if(item.name==this.zhuti){
						return cateid = item.id
					}
				})
				return cateid || ''
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/uni-input {
	    display: block;
	    font-size: 28rpx;
	    line-height: 1.2em;
	    height: 1.2em;
	    min-height: 1.2em;
	    overflow: hidden;
		color: #000;
	}
	.uni-input-placeholder{
		color: #aaa;
	}
	.pubdymanic {
		position: relative;
		background: #000;
		height: 100vh;
		.cellinfo {
			width: 90%;
			margin: auto;
			background-color: #323232;
			.infoitem {
				display: flex;
				padding: 40rpx 30rpx;
				.label {
					width: 22%;
					font-weight: bold;
					color: rgb(231, 143, 20);
				}
				.value{
					color: #aaa;
				}
				textarea{
					width: 100%;
					color: #eee;
				}
			}
			.photo{
				width: 95%;
				margin: auto;
				padding: 10rpx;
			}
		}
	}
	.vie-bott{
		width: 100%;
		position: fixed;
		bottom: 0;
		height: 120rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.bu-bott{
		width: 443rpx;
		height: 84rpx;
		border-radius: 40rpx;
		background-color: #D89E5E;
		color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.bottomOne{
		margin: 40rpx auto;
		width: 443rpx;
		height: 84rpx;
		background-color: #D6A666;
		border-radius: 40rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 35rpx;
	}
	.bottomTwo{
		margin: 40rpx auto;
		width: 443rpx;
		height: 84rpx;
		border: 1rpx solid #D6A666;
		border-radius: 40rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #D6A666;
		font-size: 35rpx;
	}
</style>
